package com.atguigui.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * P面试题 01.08.零矩阵
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/9/30 8:39
 */
public class ZeroMatrixLcci {
    public static void main(String[] args) {
        Solution solution = new ZeroMatrixLcci().new Solution();
        // TO TEST
    }

    class Solution {
        public void setZeroes(int[][] matrix) {
            int n = matrix.length;
            int m = matrix[0].length;


            Set<Integer> listI = new HashSet<>();
            Set<Integer> listJ = new HashSet<>();


            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (matrix[i][j] == 0) {
                        listI.add(i);
                        listJ.add(j);
                    }
                }
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (listI.contains(i) || listJ.contains(j)) {
                        matrix[i][j] = 0;
                    }
                }
            }


        }
    }

}
